package com.kuang.controller;

import com.kuang.common.limit.annotation.AccessIpLimiter;
import com.kuang.entity.Product;
import com.kuang.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class ProductController extends BaseController {

    @Autowired
    private ProductService productService;

    /**
     * @Description: 查询所有商品信息
     * @Param: []
     * @Author: admin
     * @return: java.util.List<com.kuang.entity.Product>
     * @Date: 2021/8/3 15:40
     */
    @GetMapping("/product/list")
    @AccessIpLimiter(limit = 5, timeout = 1)
    public List<Product> productList() {
        List<Product> productList = productService.list();
        return productList;
    }

    /**
     * @Description: 根据Id查询商品信息
     * @Param: [id]
     * @Author: admin
     * @return: com.kuang.entity.Product
     * @Date: 2021/8/3 15:43
     */
    @GetMapping("/product/get/{id}")
    @AccessIpLimiter(limit = 5, timeout = 1)
    public Product getProduct(@PathVariable("id") Long id) {
        return productService.getById(id);
    }
}

